package com.huasoft.servlet.userself;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.huasoft.dao.UserDao;
import com.huasoft.domain.User;

public class ModifyPWDServlet {

	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		String password = request.getParameter("password");
		String repassword = request.getParameter("repassword");
		if (!password.equals(repassword)) {
			request.setAttribute("msg_notequals", "两次输入密码不一致");
		} else {
			user.setPassword(password);
			UserDao userDao = new UserDao();
			boolean update = userDao.update(user);
			if (update) {
				request.setAttribute("msg_modifyPWDSuccess", "更新密码成功");
				session.setAttribute("user", user);
			} else {
				request.setAttribute("msg_modifyPWDFalse", "更新密码失败");
			}
		}
		request.getRequestDispatcher("/index.jsp").forward(request, response);
	}

}
